import com.pandorasoft.shiro.ShiroModule
import org.apache.shiro.crypto.hash.Sha256Hash

class BootStrap {

	def init = { servletContext ->
		def adminRole = ShiroRole.findByName("Administrator")
		if(!adminRole){
			adminRole = new ShiroRole(name:'Administrator')
			adminRole.addToPermissions("*:*")
			adminRole.save()
		}
		def admin = ShiroUser.findByUsername('admin')
		if(!admin){
			admin= new ShiroUser(firstName:"Administator",lastName:"User",
					username: 'admin', passwordHash: new Sha256Hash("admin").toHex(),email:'someone@gmail.com')
			admin.save()
			adminRole.addToUsers(admin)
			adminRole.save()
		}
		
		def module = new ShiroModule(name:"商户管理",root:"YES")	
		def child = new ShiroModule(name:"预约管理",root:"NO")
		module.addToChildrens(child)
		def child1 = new ShiroModule(name:"商户管理",root:"NO")
		module.addToChildrens(child1)
		def child2 = new ShiroModule(name:"用户管理",root:"NO")
		module.addToChildrens(child2)
		module.save(flush:true)
		
		def module0 = new ShiroModule(name:"约会管理",root:"YES")
		module0.addToChildrens(new ShiroModule(name:"约会管理",controllerName:"yuenar",root:"NO"))
		module0.addToChildrens(new ShiroModule(name:"约会类型管理",controllerName:"yuenarType",root:"NO"))
		module0.save(flush:true)
		
		def module1 = new ShiroModule(name:"应用端管理",root:"YES") 
		module1.addToChildrens(new ShiroModule(name:"商户分类管理",root:"NO"))
		module1.addToChildrens(new ShiroModule(name:"约会类型管理",root:"NO"))
		module1.addToChildrens(new ShiroModule(name:"节假日管理",root:"NO"))
		module1.addToChildrens(new ShiroModule(name:"消息管理",root:"NO"))
		module1.save(flush:true)

//		def module2 = new ShiroModule(name:"应用端管理",root:"YES")
//		module2.addToChildrens(new ShiroModule(name:"商户分类管理",root:"NO"))
//		module2.addToChildrens(new ShiroModule(name:"约会类型管理",root:"NO"))
//		module2.addToChildrens(new ShiroModule(name:"节假日管理",root:"NO"))
//		module2.addToChildrens(new ShiroModule(name:"消息管理",root:"NO"))
//		module2.save(flush:true)
	
		def module3 = new ShiroModule(name:"数据分析",root:"YES")
		module3.addToChildrens(new ShiroModule(name:"店铺数据分析",root:"NO"))
		module3.addToChildrens(new ShiroModule(name:"菜品数据分析",root:"NO"))
		module3.addToChildrens(new ShiroModule(name:"客户数据分析",root:"NO"))
		module3.save(flush:true)
		
		def module4 = new ShiroModule(name:"系统管理",root:"YES")
		module4.addToChildrens(new ShiroModule(name:"系统管理",root:"NO"))
		module4.addToChildrens(new ShiroModule(name:"用户管理",root:"NO"))
		module4.save(flush:true)
	
	}
	def destroy = {
	}
}
